package com.xiaoqi.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.xiaoqi.dao.MenuDao;
import com.xiaoqi.pojo.Menu;
import com.xiaoqi.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @author PC
 * creationTime: 2022/11/7 10:18
 */

@Service(interfaceClass = MenuService.class)
@Transactional
public class MenuServicekimpl implements MenuService {

    @Autowired
    private MenuDao menuDao;

    @Override
    public List<Menu> findAll() {
        return menuDao.findAll();
    }

    /**
     * 根据条件查询菜单
     * @return
     */
    @Override
    public List<Menu> findMenuByLevelOrPrentId() {
        //查询level为1的一级菜单
        List<Menu> menuList = menuDao.findMenuByLevelOrPrentId(1,null);
        for (Menu menu : menuList) {
            //查询父菜单id为当前菜单id的所有子菜单
            List<Menu> childrenMenu = menuDao.findMenuByLevelOrPrentId(null, menu.getId());
            menu.setChildren(childrenMenu);
        }
        return menuList;
    }

    /**
     * 更具角色id查询对应的菜单
     * @param roleId
     * @return
     */
    @Override
    public List<Menu> getMenu(Integer roleId) {
        return menuDao.getMenu(roleId);
    }
}
